const express = require('express')
const router = express.Router()
const fs = require('fs')


// 获取轮播图资源
router.get('/promotion/ads/search/findByPosition', (req, res) => {
    const data = fs.readFileSync('data/banner.json', { encoding: 'utf8' })
    res.json({ code: 20000, data: { content: JSON.parse(data) }, value: '获取数据成功~' })
})

// 获取推荐列表
router.get('/moment/moments/rec/default', (req, res) => {
    // column=recommend&pageSize=20&pageNum=0
    const { pageSize, pageNum } = req.query
    const resData = fs.readFileSync('data/recommend.json', { encoding: 'utf8' })
    const data = JSON.parse(resData).content.splice(pageSize * pageNum, pageSize * (pageNum * 1 + 1))
    res.json({
        code: 20000, data: {
            content: data,
            first: true,
            last: false,
            number: 0,
            numberOfElements: 20,
            size: pageSize,
            sort: null,
            totalPages: 3
        }, value: '获取数据成功~'
    })
})

// 作品
// 1.统合榜
router.get('/moment/moments/collect/original/integrated', (req, res) => {
    const { pageSize, pageNum } = req.query
    const resData = fs.readFileSync('data/IntegratedList.json', { encoding: 'utf8' })
    const data = JSON.parse(resData).content.splice(pageSize * pageNum, pageSize * (pageNum * 1 + 1))
    res.json({
        code: 20000,
        data: {
            content: data,
            number: 2,
            numberOfElements: 20,
            size: pageSize,
            sort: null,
            statistics: {
                minScore: null,
                searchSuggest: null
            },
            totalElements: 81507,
            totalPages: 4076,
            useOffset: false
        }
    })
})
// 2.热练榜
router.get('/moment/moments/collect/original/popTraining', (req, res) => {
    const { pageSize, pageNum } = req.query
    const resData = fs.readFileSync('data/popTraining.json', { encoding: 'utf8' })
    const data = JSON.parse(resData).content.splice(pageSize * pageNum, pageSize * (pageNum * 1 + 1))
    res.json({
        code: 20000,
        data: {
            content: data,
            number: 2,
            numberOfElements: 20,
            size: pageSize,
            sort: null,
            statistics: {
                minScore: null,
                searchSuggest: null
            },
            totalElements: 81507,
            totalPages: 4076,
            useOffset: false
        }
    })
})
// 3.新锐榜单/最新
router.get('/moment/moments/collect/original/newcomer', (req, res) => {
    const { pageSize, pageNum } = req.query
    const resData = fs.readFileSync('data/newcomer.json', { encoding: 'utf8' })
    const data = JSON.parse(resData).content.splice(pageSize * pageNum, pageSize * (pageNum * 1 + 1))
    res.json({
        code: 20000,
        data: {
            content: data,
            number: 2,
            numberOfElements: 20,
            size: pageSize,
            sort: null,
            statistics: {
                minScore: null,
                searchSuggest: null
            },
            totalElements: 272,
            totalPages: 14,
            useOffset: false
        }
    })
})
// 4.获取可隐藏的动态条件
router.get('/moment/properties/filter/original', (req, res) => {
    const data = fs.readFileSync('data/original.json', { encoding: 'utf8' })
    res.json({ code: 20000, data: { content: JSON.parse(data) }, value: '获取数据成功~' })
})
// 5. 多条件过滤
router.post('/moment/moments/collect/original/lastest', (req, res) => {
    const { pageSize, pageNum } = req.query
    const data = fs.readFileSync('data/collected_latested.json', { encoding: 'utf8' })
    let a = {
        "filterInfo": [
            {
                "filterCode": "avocation",
                "filterValue": ["402881ed649d628e01649d636ea7005b", "ff80808167bef94f0167bf6f6e0a1fd2"],
                "avocationNames": ["中国舞"]
            },
            {
                "filterCode": "contentType",
                "filterValue": ["video", "photo"],
                "avocationNames": ["中国舞"]
            }
        ]
    }
    res.json({ code: 20000, data: JSON.parse(data), value: '获取数据成功~' })
})

// 教程
//1.综合
router.get('/moment/moments/collect/course/integrated', (req, res) => {
    const { pageSize, pageNum } = req.query
    const resData = fs.readFileSync('data/integrated.json', { encoding: 'utf8' })
    const data = JSON.parse(resData).content.splice(pageSize * pageNum, pageSize * (pageNum * 1 + 1))
    res.json({
        code: 20000,
        data: {
            content: data,
            number: 2,
            numberOfElements: 20,
            size: pageSize,
            sort: null,
            statistics: {
                minScore: null,
                searchSuggest: null
            },
            totalElements: 9699,
            totalPages: 485,
            useOffset: false
        }
    })
})
// 2.可隐藏的动态条件
router.get('/moment/properties/filter/course', (req, res) => {
    const data = fs.readFileSync('data/course.json', { encoding: 'utf8' })
    res.json({ code: 20000, data: { content: JSON.parse(data) }, value: '获取数据成功~' })
})

// 选择我的兴趣技能
// 1.获取兴趣列表
router.get('/avocation/avocations/rec/user', (req, res) => {
    const { pageSize, pageNum } = req.query
    const resData = fs.readFileSync('data/avocations.json', { encoding: 'utf8' })
    const data = JSON.parse(resData).content.slice(pageSize * pageNum, pageSize * (pageNum * 1 + 1))
    res.json({
        code: 20000,
        data: {
            content: data,
            number: 2,
            numberOfElements: 22,
            size: pageSize,
            sort: null,
            statistics: null,
            totalElements: 1829,
            totalPages: 92,
            useOffset: false
        }
    })
})
// 2.兴趣列表_已选的
router.get('/userCenter/users/me', (req, res) => {
    const data = fs.readFileSync('data/userCenter.json', { encoding: 'utf8' })
    res.json({ code: 20000, data: JSON.parse(data), value: '获取数据成功~' })
})
// 3.兴趣列表_关键字搜索
router.get('/avocation/avocations/search/findByName', (req, res) => {
    const { name } = req.query
    const resData = fs.readFileSync('data/avocation_search.json', { encoding: 'utf8' })
    const data = JSON.parse(resData).filter(item => item.name.includes(name))
    if (!data) return res.json({ code: 20000, data: { content: null }, value: '暂无数据~' })
    res.json({ code: 20000, data: { content: data }, value: '获取数据成功~' })
})

// 课程
// 1.会员专区_动态搜索条件列表
router.get('/moment/properties/filter/vip_zone', (req, res) => {
    const data = fs.readFileSync('data/vip_zone.json', { encoding: 'utf8' })
    res.json({ code: 20000, data: JSON.parse(data), value: '获取数据成功~' })
})
// 2.会员专区_多条件课程列表
router.get('/moment/moments/collect/vip_zone/integrated', (req, res) => {
    const { pageSize, pageNum } = req.query
    const resData = fs.readFileSync('data/collect_integrated.json', { encoding: 'utf8' })
    let a = {
        "filterInfo": [
            {
                "filterCode": "avocation",
                "filterValue": ["402881ed649d628e01649d636ea60056", "402881ed649d628e01649d636ea7005b"]
            },
            {
                "filterCode": "priceRange",
                "filterValue": ["range_2_100"]
            },
            {
                "filterCode": "courseType",
                "filterValue": ["d90d3359dea27b2425db29fb81226186"]
            }
        ]
    }
    // const data = JSON.parse(resData).content.splice(pageSize * pageNum, pageSize * (pageNum * 1 + 1))
    res.json({
        code: 20000,
        data: {
            content: JSON.parse(resData),
            number: 2,
            numberOfElements: 22,
            size: pageSize,
            sort: null,
            statistics: null,
            totalElements: 1829,
            totalPages: 92,
            useOffset: false
        }
    })
})
// 3.会员专区_多条件搜索_价格
router.get('/moment/moments/collect/vip_zone/sellCountDesc', (req, res) => {
    const { pageNum, pageSize } = req.query

    let a = {
        "filterInfo": [
            {
                "filterCode": "avocation",
                "filterValue": [
                    "ff80808167bef94f0167bf6f6e0a1fd2", "402881ed649d628e01649d636ea60056"]
            },
            { "filterCode": "priceRange", "filterValue": ["range_0_2"] }
        ]
    }
    const data = fs.readFileSync('data/vip_search_price.json', { encoding: 'utf8' })
    res.json({
        code: 20000,
        data: JSON.parse(data),
        value: '获取数据成功~'
    })
})
// 5.专题
router.get('/moment/activityZones/collect/default', (req, res) => {
    const { pageSize } = req.query
    const resData = fs.readFileSync('data/activityZones.json', { encoding: 'utf8' })
    const data = JSON.parse(resData).content.splice(0, pageSize)
    res.json({
        code: 20000,
        data: {
            content: data,
            number: 0,
            numberOfElements: 14,
            size: pageSize,
            sort: null,
            statistics: null,
            totalElements: 14,
            totalPages: 1,
            useOffset: false
        },
        value: '获取数据成功~'
    })
})

// 练习室
// 1.浏览历史列表
router.get('/moment/viewRecords', (req, res) => {
    const { pageSize, pageNum = 0 } = req.query
    const resData = fs.readFileSync('data/viewRecords.json', { encoding: 'utf8' })
    const data = JSON.parse(resData).content.splice(pageSize * pageNum, pageSize * (pageNum * 1 + 1))
    res.json({
        code: 20000,
        data: {
            content: data,
            number: 0,
            numberOfElements: 20,
            size: pageSize,
            sort: null,
            statistics: null,
            totalElements: 13,
            totalPages: 2,
            useOffset: false
        },
        value: '获取数据成功~'
    })
})

// 交流
// 1.系统通知
router.get('/message/userMessages/search/findByType', (req, res) => {
    const { pageSize, pageNum } = req.query
    const resData = fs.readFileSync('data/viewRecords.json', { encoding: 'utf8' })
    const data = JSON.parse(resData).content.splice(pageSize * pageNum, pageSize * (pageNum * 1 + 1))
    res.json({
        code: 20000,
        data: {
            content: data,
            number: 0,
            numberOfElements: 20,
            size: pageSize,
            sort: null,
            statistics: null,
            totalElements: 13,
            totalPages: 2,
            useOffset: false
        },
        value: '获取数据成功~'
    })
})

// 我的
// 1.个人资料
router.get('/userCenter/users/me', (req, res) => {
    const data = fs.readFileSync('data/me.json', { encoding: 'utf8' })
    res.json({
        code: 20000,
        data: JSON.parse(data),
        value: '获取数据成功~'
    })
})
// 2.我的会员
router.get('/setup/setups/search/findByGroupType', (req, res) => {
    const data = fs.readFileSync('data/vip_group.json', { encoding: 'utf8' })
    res.json({
        code: 20000,
        data: JSON.parse(data),
        value: '获取数据成功~'
    })
})
// 视频详情
// 1.资源
router.get('/moment/moments/:id', (req, res) => {
    const { id } = req.params
    const { source } = req.query
    const data = fs.readFileSync('data/videoSource.json', { encoding: 'utf8' })
    res.json({
        code: 20000,
        data: JSON.parse(data),
        value: '获取数据成功~'
    })
})

module.exports = router